﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}

<script src="~/Content/adminDefault/js/default.js"></script>
<script>
    var _category = request('BillType');//单据类型
    var _Type = "";//工单工作类型
    var _organizeid = "@LeSoft.Application.Code.OperatorProvider.Provider.Current().CompanyId";
    $(function () {
        InitialPage();
        GetTree();
        GetGrid();
    });

    //初始化页面
    function InitialPage() {
        //layout布局
        $('#layout').layout({
            applyDemoStyles: true,
            onresize: function () {
                $(window).resize()
            }
        });
        //resize重设(表格、树形)宽高
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth(($('.gridPanel').width()));
                $("#gridTable").setGridHeight($(window).height() - 165.5);
            }, 200);
            e.stopPropagation();

        });

        //组织机构
        $("#PStructTree").ComboBoxTree({
            url: "../../BaseManage/Organize/GetTreeJsonById",
            height: "250px",
            click: function (item) {
                if (_organizeid != item.id) {
                    _organizeid = item.id;
                    $('#btn_Search').trigger("click");
                }
            }
        });
        $("#PStructTree").ComboBoxTreeSetValue(_organizeid);

    }

    function GetTree() {
        var _url = "";
        if (_category == "1") {//开店
            _url = "../../DailyEventManage/OpenShop/GetDataItemTreeJson?EnCode=OpenShopWorkType";
        }
        else if (_category == "2") {//闭店
            _url = "../../DailyEventManage/OpenShop/GetDataItemTreeJson?EnCode=CloseShopWorkType";
        }
        else {
            _url = "";
        }
        var item = {
            url: _url,
            onnodeclick: function (item) {
                
                _Type = item.id;
                $('#btn_Search').trigger("click");
            }
        };
        //初始化
        $("#itemTree").treeview(item);
    }


    //加载表格
    function GetGrid() {
        var selectedRowIndex = 0;
        var queryJson = $("#queryCondition").GetWebControls();
        var $gridTable = $('#gridTable');
        $gridTable.jqGrid({
            url: "../../DailyEventManage/OpenShop/GetPageListShopBill?Type=" + _Type + "&BillType=" + _category + "&organizeid=" + _organizeid,
            postData: queryJson,
            datatype: "json",
            height: $(window).height() - 165.5,
            autowidth: true,
            colModel: [
                { label: "主键", name: "Id", hidden: true },
                { label: "单号", name: "Code", index: "Code", width: 200, align: "center" },
                { label: "日期", name: "Date", index: "Date", width: 80, align: "center" },
                { label: "类型", name: "Type", index: "Type", width: 150, align: "center" },
                {
                    label: "单据状态", name: "State", index: "State", width: 100, align: "center",
                    formatter: function (cellvalue, options, rowObject) {
                        
                        switch (cellvalue) {
                            case 0: return "<span class=\"label label-default\">未派单</span>"; break;
                            case 1: return "<span class=\"label label-success\">派单中</span>"; break;
                            case 2: return "<span class=\"label label-primary\">进行中</span>"; break;
                            case 3: return "<span class=\"label label-warning\">已完成</span>"; break;
                            case 4: return "<span class=\"label label-danger\">已退单</span>"; break;
                            case 5: return "<span class=\"label label-danger\">已取消</span>"; break;
                            default: return ""; break;
                        }

                    }
                },
                {
                    label: "是否审核", name: "AuditMark", index: "AuditMark", width: 150, align: "center",
                    formatter: function (cellvalue, options, rowObject) {
                        if (cellvalue == 1) {
                            return "已审核；审核人:" + rowObject.AuditUserName + " 审核时间：" + rowObject.AuditDate;
                        } else { return "<span class=\"label label-default\">未审核</span>"; }
                    }
                },
                {
                    label: "完成情况", name: "CompleteState", index: "CompleteState", width: 150, align: "center",
                    formatter: function (cellvalue, options, rowObject) {
                        if (cellvalue == 1) {
                            return "已完成；完成人:" + rowObject.CompleteMan + " 完成时间：" + rowObject.CompleteDate;
                        } else { return ""; }
                    }
                }
            ],
            viewrecords: true,
            rowNum: 30,
            rowList: [30, 50, 100],
            pager: "#gridPager",
            sortname: 'Date',
            sortorder: 'desc',
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            onSelectRow: function (status) {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            }
        });
        //查询条件
        $("#queryCondition .dropdown-menu li").click(function () {
            var text = $(this).find('a').html();
            var value = $(this).find('a').attr('data-value');
            $("#queryCondition .dropdown-text").html(text).attr('data-value', value)
        });
        //查询事件
        $("#btn_Search").click(function () {
            var queryJson = $("#queryCondition").GetWebControls();
            $gridTable.jqGrid('setGridParam', {
                url: "../../DailyEventManage/OpenShop/GetPageListShopBill?Type=" + _Type + "&BillType=" + _category + "&organizeid=" + _organizeid,
                postData: queryJson
            }).trigger('reloadGrid');
        });
        //查询回车
        $('#keyword').bind('keypress', function (event) {
            if (event.keyCode == "13") {
                $('#btn_Search').trigger("click");
            }
        });
    }

    //批量新增
    function btn_addBatch() {
        dialogOpen({
            id: "Form",
            title: '批量新增工单',
            url: '/DailyEventManage/OpenShop/BatchForm?BillType=' + _category + "&Type=" + _Type,
            width: "500px",
            height: "370px",
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick();
            }
        });
    }
    //新增
    function btn_add() {
        dialogOpen({
            id: "Form",
            title: '新增工作单',
            url: '/DailyEventManage/OpenShop/Form?BillType=' + _category + "&Type=" + _Type,
            width: "1100px",
            height: "750px",
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick();
            }
        });
    };

    //编辑
    function btn_edit() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (checkedRow(keyValue)) {
            dialogOpen({
                id: "Form",
                title: '编辑工作单',
                url: '/DailyEventManage/OpenShop/Form?keyValue=' + keyValue + "&BillType=" + _category,
                width: "1100px",
                height: "750px",
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick();
                }
            });
        }
    };

    //删除
    function btn_delete() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (keyValue) {
            $.RemoveForm({
                url: "../../DailyEventManage/OpenShop/RemoveForm",
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#gridTable").trigger("reloadGrid");
                }
            })
        } else {
            dialogMsg('请选择需要删除的单据！', 0);
        }
    }

    //设置工作类型
    function btn_Type() {
        dialogOpen({
            id: "TypeForm",
            title: '设置工作类型',
            url: '/DailyEventManage/OpenShop/TypeIndex?BillType=' + _category,
            width: "1100px",
            height: "750px",
            btn: null
        });
    };

    //设置工作项目
    function btn_Item() {
        top.tablist.newTab({ id: 'ItemForm' + _category, title: '设置工作项目', closed: true, icon: "fa fa fa-eye", url: top.contentPath + '/DailyEventManage/OpenShop/ItemIndex?BillType=' + _category });
    };
    //设置工作内容
    function btn_Content() {
        top.tablist.newTab({ id: 'ContentForm' + _category, title: '设置工作内容', closed: true, url: top.contentPath + '/DailyEventManage/OpenShop/ContentIndex?Category=' + _category });
    };
</script>

<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-west">
        <div class="west-Panel" style="height: 98%;">
            <div class="panel-Title" style="padding:0px;">
                <div id="PStructTree" type="selectTree" class="ui-select"></div>
            </div>
            <div id="itemTree"></div>
        </div>
    </div>
    <div class="ui-layout-center">
        <div class="center-Panel">
         
            <div class="titlePanel">
                <div class="title-search">
                    <table id="queryCondition">
                        <tr>
                            <td>查询条件</td>
                            <td >
                                <div style="float: left; width: 45%;">
                                    <input id="StartTime" readonly style="  margin-top: 18px;" type="text" value="@DateTime.Now.AddDays(-Convert.ToInt32(DateTime.Now.Day) + 1).ToString("yyyy-MM-dd")" class="form-control input-wdatepicker" onfocus="WdatePicker({maxDate:'%y-%M-%d'})">
                                </div>
                                <div style="float: left; width: 10%; text-align: center;">至</div>
                                <div style="float: left; width: 45%;">
                                    <input id="EndTime" readonly style="  margin-top: 18px;" type="text" value="@DateTime.Now.AddMonths(1).AddDays(-Convert.ToInt32(DateTime.Now.Day)).ToString("yyyy-MM-dd")" class="form-control input-wdatepicker" onfocus="WdatePicker({})">
                                </div>
                            </td>
                            <td style="padding-left: 5px;">
                                <a id="btn_Search" class="btn btn-primary"><i class="fa fa-search"></i>&nbsp;查询</a>
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="toolbar">
                    <div class="btn-group">
                        <a id="lr-replace" class="btn btn-default" onclick="reload();"><i class="fa fa-refresh"></i>&nbsp;刷新</a>
                        <a id="lr-add" class="btn btn-default" onclick="btn_add()"><i class="fa fa-plus"></i>&nbsp;新增</a>
                        <a id="lr-addBatch" class="btn btn-default" onclick="btn_addBatch()"><i class="fa fa-sign-in"></i>&nbsp;批量新增</a>
                        <a id="lr-edit" class="btn btn-default" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑</a>
                        <a id="lr-delete" class="btn btn-default" onclick="btn_delete()"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
                    </div>
                    <div class="btn-group">
                        <a id="lr-more" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                            <i class="fa fa-reorder"></i>&nbsp;更多操作<span class="caret"></span>
                        </a>
                        <ul class="dropdown-menu pull-right">
                            <li id="lr-type"><a onclick="btn_Type()"><i></i>&nbsp;设置工作类型</a></li>
                            <li id="lr-item"><a onclick="btn_Item()"><i></i>&nbsp;设置工作项目</a></li>
                            <li id="lr-content"><a onclick="btn_Content()"><i></i>&nbsp;设置工作内容词典</a></li>
                            @*<li id="lr-enabled"><a onclick=""><i></i>&nbsp;选项</a></li>*@
                        </ul>
                        <script>$('.toolbar').authorizeButton()</script>
                    </div>
                </div>
            </div>
            <div class="gridPanel">
                <table id="gridTable"></table>
                <div id="gridPager"></div>
            </div>
        </div>
    </div>
</div>


